/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.manage.service;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.customer.core.repository.entity.PartnerEntity;
import info.peigen.hotpot.business.customer.manage.convertor.PartnerManageConvertor;
import info.peigen.hotpot.business.customer.manage.form.PartnerManageCreateForm;
import info.peigen.hotpot.business.customer.manage.form.PartnerManageEditForm;
import info.peigen.hotpot.business.customer.manage.form.PartnerManageSearchForm;
import info.peigen.hotpot.business.customer.manage.info.PartnerManageInfo;
import info.peigen.hotpot.business.customer.manage.repository.service.PartnerManageRepository;
import info.peigen.hotpot.common.core.result.PageResult;
import org.beetl.sql.core.query.LambdaQuery;
import org.beetl.sql.core.query.Query;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * <b>(PartnerManageService)</b>
 * 管理后台 "合作伙伴" 服务
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023-09-09
 */
@SuppressWarnings("unused")
@Component
public class PartnerManageService {
    @Inject
    PartnerManageRepository partnerManageRepository;

    public PageResult<PartnerManageInfo> page(PartnerManageSearchForm form) {
        LambdaQuery<PartnerEntity> lambdaQuery = partnerManageRepository.getMapper().createLambdaQuery()
                .andLike(PartnerEntity::getPartnerId, Query.filterLikeEmpty(form.getPartnerId(), false, true))
                .andLike(PartnerEntity::getPartnerName, Query.filterLikeEmpty(form.getPartnerName(), false, true))
                .andLike(PartnerEntity::getStatus, Query.filterLikeEmpty(form.getStatus(), false, true));

        return partnerManageRepository.page(form.getPageNum(), form.getPageSize(), lambdaQuery, PartnerManageConvertor::convertToInfo);
    }

    public void create(PartnerManageCreateForm form) {
        PartnerEntity entity = BeanUtil.copyProperties(form, PartnerEntity.class);
        partnerManageRepository.save(entity);
    }

    public void edit(PartnerManageEditForm form) {
        PartnerEntity entity = BeanUtil.copyProperties(form, PartnerEntity.class);
        partnerManageRepository.saveOrUpdate(entity);
    }

    public void remove(Integer id) {
        partnerManageRepository.delete(id);
    }
}